{extend name="$BASE_LIST" /}
{block name="body"}
<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">{$page_nav}</span></div>
    <ul class="tab_navs" id="js_tab_navs">
        <li class="{if condition='$status eq 0'}current{/if}"><a class="pjax" href="{:getUrl('index','status=0')}">未审核</a></li>
        <li class="{if condition='$status eq 1'}current{/if}"><a class="pjax" href="{:getUrl('index','status=1')}">已审核</a></li>
        <li class="{if condition='$status eq -1'}current{/if}"><a class="pjax" href="{:getUrl('index','status=-1')}">不通过</a></li>
    </ul>
    <div id="js_main_header" class="ui-form main_header">
        <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
            <input type="text" id="js_keyword" placeholder="请输入用户名称" value="" class="frm_input" />
        </span>
    </div>
    <table id="grid-table">
        <thead frozen="true">
        <th data-options="field:'username',width:100,align:'center'">用户名称</th>
        <th data-options="field:'ref_no',width:200,align:'center'">充值单号</th>
        <th data-options="field:'amount',width:100, align:'center'">充值金额</th>
        <th data-options="field:'identity',width:100, align:'center'">金额标识</th>
        <th data-options="field:'total_amount',width:100, align:'center'">充值总金额</th>
        
        <th data-options="field:'status',width:100, align:'center',formatter:formatStatus">审核状态</th>
        <th data-options="field:'pic',width:100, align:'center',formatter:formatPic">凭证</th>
        <th data-options="field:'add_time',width:140,align:'center'">创建时间</th>
        <th data-options="field:'update_time',width:140,align:'center'">更新时间</th>
        
        <th data-options="field:'_oper',width:250,halign:'center',formatter: formatOper">操作</th>
    </table>
</div>

{/block}
{block name="script"}
<script type="text/javascript">
    var status = '{$status}'

    function formatOper(value, row, index) {
        if (row.status == 0){
            var html = '<span class="grid-operation">';

            html += '<button type="button" onclick="doCheck(' + row['id'] + ',1)" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>通过</button>';
            html += '<button type="button" onclick="doCheck(' + row['id'] + ',-1)" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>不通过</button>';
            html += '</span>';

        }
        return html;
    }
    //状态
    function formatStatus(value,row,index){
        if(row['id']){
            switch (value){
                case 1 :
                    var text = '<span style="color:red">已审核</span>';
                    break;
                case -1 :
                    var text = '<span style="color:red">未通过</span>';
                    break;
                default:
                    var text = '<span style="color:red">未审核</span>';

            }
            return text;
        }
    }
    //查看图片
    function formatPic(value,row,index){
        if(row['id']){
            var html = '<button type="button" onclick="showPic('+row['id']+')" class="btn btn-xs btn-default btn-primary">点我查看</button>';
            return html;
        }
    }
    function showPic(id){
        var url = getURL('show_pic', 'id=' + id);
        openBarWin('查看凭证', 700, 500, url, function () {
            reload();
        }, ['确定','取消']);
    }
    //审核
    function doCheck(id,status){
        var title = '审核通过?';
        if(status == -1)
            title = '审核不通过?';
        confirm(title, function () {
            var url = getURL('doCheck');
            $.getJSON(url, {id: id,status:status}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList','status='+status),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20,
            showFooter:true,
            onLoadSuccess: function(data){
                $('#grid-table').datagrid('reloadFooter', [
                    {
                        username: '统计',
                        amount: data.count_total
                    }
                ]);
            }
        });
        //设置分页控件 
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10 
            pageList: [20, 30, 50]
        });
    });

//    function doCheck(id,status){
//        var title = '确认要解冻此用户吗?';
//        if(status == 1)
//            title = '确认要冻结此用户吗?';
//        confirm(title, function () {
//            var url = getURL('change_frozen');
//            $.getJSON(url, {id: id,status:status}, function (json) {
//                if (json.success)
//                    reload();
//                else
//                    alert(json.message);
//            });
//        });
//    }
//
//    function view_balance(id){
//        var url = getURL('view_balance', 'id=' + id);
//        openBarWin('资产', 400, 400, url, function () {
//            reload();
//        }, ['确定','取消']);
//    }
//
//    function add_coin_stock(id) {
//        var url = getURL('add_coin_stock', 'id=' + id);
//        openBarWin('拨币', 400, 400, url, function () {
//            reload();
//        }, ['确定','取消']);
//    }
//
//    function edit(id) {
//        var url = getURL('edit', 'id=' + id);
//        openBarWin('编辑', 1000, 500, url, function () {
//            reload();
//        }, ['确定','取消']);
//    }
//    function auth(id) {
//        var url = getURL('auth', 'id=' + id);
//        openBarWin('认证用户', 1000, 400, url, function () {
//            reload();
//        }, ['确定','取消']);
//    }
//
//    function del(id) {
//        confirm("确认要删除此会员吗？逻辑删除,以备还原数据,会员数据依然会存在于数据库中", function () {
//            var url = getURL('del');
//            $.getJSON(url, {id: id}, function (json) {
//                if (json.success)
//                    reload();
//                else
//                    alert(json.message);
//            });
//        });
//    }

    $("#js_search").click(function () {
        reload();
    });
    function reload() {
        var keyword = $("#js_keyword").val();
        $('#grid-table').datagrid('reload', {keyword: keyword});
    }
    $("#type").change(function () {
        var keyword = $("#js_keyword").val();
        $('#grid-table').datagrid('reload', {keyword: keyword});
    });
</script>
{/block}